/**
 * @fileOverview 菜单
 * @author goodzsq@gmail.com
 */
var BaseClass = gg.module('ui.jq.Component');
module.exports = gg.createClass({
    attributes: {
        items: {
            type: 'datatype.Array',
            defaultValue: [],
            setter: function(v) {
                this.defaultSetter('items', v);
                this.refresh();
            }
        },
        style: {
            type: 'datatype.String',
            defaultValue: 'pills',
            editor: {type: 'list', data: ['pills', 'tabs', 'stacked']},
            setter: function(v, oldValue) {
                this.defaultSetter('style', v);
                if (oldValue === 'stacked') {
                    this.el.removeClass('nav-pills').removeClass('nav-stacked');
                } else {
                    this.el.removeClass('nav-' + oldValue);
                }
                if (v === 'stacked') {
                    this.el.addClass('nav-pills').addClass('nav-stacked');
                } else {
                    this.el.addClass('nav-' + v);
                }
            }
        }
    },
    methods: {
        refresh: function() {
            if (!this.inited) {
                return;
            }
            var items = this.get('items');
            this.el.children().remove();
            for (var i = 0; i < items.length; i++) {
                if (gg.type(items[i]) === 'object') {
                    items[i]['href'] = items[i]['href'] || '#';
                    var item = $('<li>').append('<a href="' + items[i]['href'] + '">' + items[i]['title'] + '</a>');
                    if (items[i]['disabled']) {
                        item.addClass('disabled');
                    }
                    if (items[i]['active']) {
                        item.addClass('active');
                    }
                    this.el.append(item);
                }
            }
        },
        /**
         * @override
         */
        createElement: function() {
            this.el = $('<ul id="' + this.cid + '" class="ui nav">');
        }
    },
    events: {
    }
}, BaseClass, []);